// UdpLocalSocket.cpp : implementation file
//

#include "stdafx.h"
#include "PublicDNSPluginService.h"
#include "UdpLocalSocket.h"
#include "MainWorkerThread.h"
#include "Trace.h"
#include "UdpLocalSocket.tmh"


// CUdpLocalSocket

CUdpLocalSocket::CUdpLocalSocket()
: m_pOwnerThread(NULL)
{
}

CUdpLocalSocket::~CUdpLocalSocket()
{
}


// CUdpLocalSocket member functions


void CUdpLocalSocket::OnReceive(int nErrorCode)
{
    BOOL    bRet;
    TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_UDP_LOCAL_SOCKET, "%!FUNC! line:%!LINE! %!LEVEL! Enter");
    if (WSAENETDOWN == nErrorCode)
    {
        TraceEvents(
            TRACE_LEVEL_FATAL,
            TRACE_UDP_LOCAL_SOCKET,
            "%!FUNC! line:%!LINE! %!LEVEL! The collapse of a subsystem \"WinSock\"."
            );
        m_pOwnerThread->m_nRetCode = nErrorCode;
        bRet = m_pOwnerThread->PostThreadMessage(
            WM_QUIT,
            m_pOwnerThread->m_nRetCode,
            0
            );
        CAsyncSocket::OnReceive(nErrorCode);
        return;
    }
    bRet = m_pOwnerThread->m_oDnsResponceEvent.SetEvent();
    CAsyncSocket::OnReceive(nErrorCode);
    TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_UDP_LOCAL_SOCKET, "%!FUNC! line:%!LINE! %!LEVEL! Exit");
}
